package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.widget.TextView;

import java.util.Timer;
import java.util.TimerTask;

public class SplashActivity extends AppCompatActivity {
    TextView tv_version;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);//改变屏幕方向
        init();
    }

    private void init() {
        tv_version=(TextView) findViewById(R.id.tv_version/*版本号控件ID*/);
        try{
                              /*得到软件包         得到软件        得到包
                                管理器            包信息          装名称*/
            PackageInfo Info=getPackageManager().getPackageInfo(getPackageName(),0);//获取版本号信息
            tv_version.setText("v"+Info.versionName);
        }
        catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        Timer timer=new Timer();
        TimerTask timerTask=new TimerTask() {
            @Override
            public void run() {
                Intent intent=new Intent(SplashActivity.this, MainActivity.class);//跳转
                startActivity(intent);
                /*欢迎界面文件名*/SplashActivity.this.finish();

            }
        };
        timer.schedule(timerTask,3000);//延迟三秒执行
    }
}